'use strict';
module.exports = {
	/**
	 * XXXnameXXX
	 * @url admin/pages/kh/admin/get_token 前端调用的url参数地址
	 * data 请求参数
	 * @param {String} params1  参数1
	 */
	main: async (event) => {
		let {
			data = {}, userInfo, util, filterResponse, originalParam
		} = event;
		let {
			customUtil,
			uniID,
			config,
			pubFun,
			vk,
			db,
			_
		} = util;
		let {
			uid,
			appid,
		} = data;
		let res = {
			code: 0,
			msg: ""
		};
		// 业务逻辑开始-----------------------------------------------------------

		let appid2 = "wxeecc3404641c6d6d";
		let appsecret2 = "55cbc07ba6d5e3d8a45a76466eb00360"
		//通过appid查询对应的appsecret,
		let app = await db.collection('a_appid').where({ appid: appid }).get()
		if(app.data.length > 0){
			let tv_appid = app.data[0].tv_appid || "";
			if(tv_appid){
				let app2 = await db.collection('a_appid').where({ appid: tv_appid }).get()
				if(app2.data.length > 0){
					appid2 = tv_appid;
					appsecret2 = app2.data[0].appsecret;
				}
			}
		}
		res.access_token = await vk.openapi.weixin.auth.getAccessToken({
			appid: appid2,
			appsecret: appsecret2
		});


		// 业务逻辑结束-----------------------------------------------------------
		return res;
	}
}